package cn.htsyb.synergy.security.bean.param;

import cn.htsyb.synergy.orm.jpa.criterion.ExpressBuilder;
import cn.htsyb.synergy.orm.jpa.criterion.QueryExpress;
import cn.htsyb.synergy.orm.jpa.model.param.AbsStandardParam;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;

import java.util.List;
/**
 * 资源权限 参数类
 * codeMaker at 2020-07-14
 * @author lakeside hubin_yuan.410@hotmail.com
 * @since 2020-07-14
 */
@Setter
@Getter
@Schema(description = "资源权限参数")
public class SecurityPermissionParam extends AbsStandardParam {
    /**层级名称*/
    @Schema(name = "layerName", description = "层级名称 ")
    protected  String layerName;
    /**层级*/
    @Schema(name = "level", description = "层级 ")
    protected  Integer level;
    /**模型*/
    @Schema(name = "model", description = "模型 ")
    protected  String model;
    /**名称*/
    @Schema(name = "name", description = "名称 ")
    protected  String name;
    /**上级主键*/
    @Schema(name = "parentId", description = "上级主键 ")
    protected  String parentId;
    /**权限编码*/
    @Schema(name = "authCode", description = "权限编码 ")
    protected  String authCode;
    /**归属系统*/
    @Schema(name = "vestedSystem", description = "归属系统 ")
    protected  String vestedSystem;
    /**访问路径*/
    @Schema(name = "visitUrl", description = "访问路径 ")
    protected  String visitUrl;

    /**通用过滤*/
    @Schema(name = "filter", description = "通用过滤")
    protected String filter;

    @Override
    public List<QueryExpress> searchCriterion() {
        return ExpressBuilder.instance(super.searchCriterion())
                    .addExpressOfOperator(!StringUtils.isEmpty(layerName), "layerName", QueryExpress.Operator.EQ, layerName)
                    .addExpressOfOperator(!ObjectUtils.isEmpty(level), "level", QueryExpress.Operator.EQ, level)
                    .addExpressOfOperator(!StringUtils.isEmpty(model), "model", QueryExpress.Operator.EQ, model)
                    .addExpressOfOperator(!StringUtils.isEmpty(name), "name", QueryExpress.Operator.EQ, name)
                    .addExpressOfOperator(!StringUtils.isEmpty(parentId), "parentId", QueryExpress.Operator.EQ, parentId)
                    .addExpressOfOperator(!StringUtils.isEmpty(authCode), "authCode", QueryExpress.Operator.EQ, authCode)
                    .addExpressOfOperator(!StringUtils.isEmpty(vestedSystem), "vestedSystem", QueryExpress.Operator.EQ, vestedSystem)
                    .addExpressOfOperator(!StringUtils.isEmpty(visitUrl), "visitUrl", QueryExpress.Operator.EQ, visitUrl)
                .build();
    }

    @Override
    public List<QueryExpress> filterCriterion() {
        boolean bool=!StringUtils.isEmpty(filter);

        return ExpressBuilder.instance(super.filterCriterion())
                /*需要自行根据索引调整可支持的通用查询字段，切不可全字段通用查询
                .addExpressOfOperator(bool,"layerName",QueryExpress.Operator.LIKE, filter)
                .addExpressOfOperator(bool,"model",QueryExpress.Operator.LIKE, filter)
                .addExpressOfOperator(bool,"name",QueryExpress.Operator.LIKE, filter)
                .addExpressOfOperator(bool,"parentId",QueryExpress.Operator.LIKE, filter)
                .addExpressOfOperator(bool,"authCode",QueryExpress.Operator.LIKE, filter)
                .addExpressOfOperator(bool,"vestedSystem",QueryExpress.Operator.LIKE, filter)
                .addExpressOfOperator(bool,"visitUrl",QueryExpress.Operator.LIKE, filter)
                 */
                .build();
    }
}